<?
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/

$App->sApplicationCSS = "incident.css";

switch($_REQUEST["page"])
{
	case "IncidentView":
		include_once("options.inc");
		$pageParams["title"]="View Incident";
		$pageParams["include"]="incident_view.inc";
		
		
		$Content->AddOption("opt8", "Save", 1, "document.f.submit();", "save2.gif");
		$Content->AddOption("break8", "", 4, "#");
		
		$Content->AddOption("opt1", "Add Comment", 0, "{$_SERVER["PHP_SELF"]}?page=AddComment&incidentID={$_REQUEST["ID"]}", "");
		
		if ($BigDaddy->IsUserAllowedByAction("incident-edit"))
		{
			$Content->AddOption("break1", "", 4, "#");
			$Content->AddOption("opt2", "Edit Report", 0, "{$_SERVER["PHP_SELF"]}?page=EditReport&ID={$_REQUEST["ID"]}", "");
			
		}
		
		if ($BigDaddy->IsUserAllowedByAction("incident-admin"))
		{
			$Content->AddOption("break2", "", 4, "#");
			$Content->AddOption("opt3", "Delete Report", 0, "query_incident.php?action=deletereport&ID={$_REQUEST["ID"]}", "");
			
		}
		
		break;
	case "IncidentAddNew":
		include_once("options.inc");
		$pageParams["title"]="Add New Incident Report";
		$pageParams["include"]="incident_form.inc";
		
		$Content->AddOption("opt8", "Save", 1, "document.f.submit();", "save2.gif");
		
		$sType = "add";
		break;
	case "IncidentTimelineXML":
		$pageParams["noDisplay"] = 1;
		header('Content-Type: text/xml');
		header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
		header("Cache-Control: no-cache");
		header("Pragma: no-cache");
		
		$aIncident = $BigDaddyData->GetIncidents();
		
	
		//ob_start();
		if (is_array($aIncident))
		{
			echo '<?xml version="1.0" encoding="UTF-8"?>
		<data>';
			foreach ($aIncident as $aRow)
			{
			?>            
				<event 
					start="<?=get_time_str($aRow["incidentStart"], "timeline");?>"
					<?
					if ($aRow["incidentEnd"] > $aRow["incidentStart"])
					{
						?>
						end="<?=get_time_str($aRow["incidentEnd"], "timeline");?>"
						<?
					}
					?>
					title="<?=htmlspecialchars($aRow["title"]);?>"
				>
				Posted By: <?=$aRow["postedBy"];?> on <?=get_time_str($aRow["postedTime"], 1);?>
				<?=htmlspecialchars($aRow["description"]);?>
				</event>
				<?
			}
			echo "</data>";
		}
		//$pageParams["content"] = ob_get_clean();
		break;
	case "IncidentTimeline":
		include_once("options.inc");
		
		$displayParams["jsTimeline"] = true;
		$displayParams["jsTimelineData"] = $_SERVER["PHP_SELF"]."?page=IncidentTimelineXML";
		$displayParams["jsTimelineOptions"]["topCentreDate"] = get_time_str(time()-(4*3600),"timeline");
		$displayParams["jsTimelineOptions"]["bottomCentreDate"] = get_time_str(time()-(4*3600),"timeline");
		$displayParams["jsTimelineOptions"]["topIntervalUnit"]="DAY";
		$displayParams["jsTimelineOptions"]["bottomIntervalUnit"]="MONTH";
		
		$pageParams["title"]="View Incident Timeline";
		$pageParams["include"]="incident_timeline.inc";
		break;
	case "AddComment":
		include_once("options.inc");
		
		$aIncident = $BigDaddyData->GetIncidentByID($_REQUEST["incidentID"]);
		
		$Content->AddOption("opt8", "Save", 1, "document.f.submit();", "save2.gif");
		
		$pageParams["title"]="Add Comment: ".$aIncident["title"];
		$pageParams["include"]="comment_form.inc";
		$sType = "add";
		break;
	case "EditComment":
		include_once("options.inc");
		
		$aIncident = $BigDaddyData->GetIncidentByID($_REQUEST["incidentID"]);
		
		$Content->AddOption("opt8", "Save", 1, "document.f.submit();", "save2.gif");
		
		$pageParams["title"]="Edit Comment: ".$aIncident["title"];
		$pageParams["include"]="comment_form.inc";
		$sType = "edit";
		break;
	case "EditReport":
		include_once("options.inc");
		$pageParams["title"]="Edit Incident Report";
		$pageParams["include"]="incident_form.inc";
		$sType = "edit";
		
		$Content->AddOption("opt8", "Save", 1, "document.f.submit();", "save2.gif");
		$Content->AddOption("break8", "", 4, "#");
		
		$Content->AddOption("opt2", "View Report", 0, "{$_SERVER["PHP_SELF"]}?page=IncidentView&ID={$_REQUEST["ID"]}", "");
		
		break;
	case "":
		/*
		$Content->AddOption("cat_txt", "Category:", 3, "");
		$Content->AddOption("cat", "", 2, "javascript:location.href=this.options[this.selectedIndex].value", null, $aCatToLinks);
		$Content->AddOption("break1", "", 4, "#");
		$Content->AddOption("opt1", "Show All", 0, "{$_SERVER["PHP_SELF"]}?page=CrontabIndex", "");
		$Content->AddOption("break2", "", 4, "#");
		$Content->AddOption("opt2", "Show Running", 0, "{$_SERVER["PHP_SELF"]}?page=CrontabIndex&show_only=running", "");
		$Content->AddOption("break3", "", 4, "#");
		$Content->AddOption("opt3", "Only Enabled", 0, "{$_SERVER["PHP_SELF"]}?page=CrontabIndex&show_only=enabled", "");
		$Content->AddOption("break4", "", 4, "#");
		$Content->AddOption("opt4", "Only Disabled", 0, "{$_SERVER["PHP_SELF"]}?page=CrontabIndex&show_only=disabled", "");
		$Content->AddOption("break5", "", 4, "#");
		$Content->AddOption("opt5", "Only Delayed", 0, "{$_SERVER["PHP_SELF"]}?page=CrontabIndex&show_only=delayed", "");

		$pageParams["title"]="BDv3: Crontab Control";
		$pageParams["sectiontitle"]="crontab";
		$pageParams["include"]=$_SERVER["DOCUMENT_ROOT"]."/crontab/index.inc";
		*/
	default:
		include_once("options.inc");
		$pageParams["title"]="BigDaddy: Incident Reports";
		$pageParams["include"]="index.inc";
		break;
}
?>
